package com.zhangkeyou.map.mapweb.handler;

import com.zhangkeyou.map.mapweb.domain.entity.Status;
import com.zhangkeyou.map.mapweb.exception.DefinitionException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: 张克友
 * @create: 2023-09-03 11:56
 * @description: 全局Exception控制
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     *
     */
    @ExceptionHandler(value = DefinitionException.class)
    @ResponseBody
    public Status bizExceptionHandler(DefinitionException e) {
        return Status.defineError(e);
    }

    /**
     * 处理其他异常
     *
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Status exceptionHandler(Exception e) {
        return new Status(400,e.getMessage(),"error");
    }
}
